package com.es.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.es.dto.SpecParamDTO;
import com.es.entity.goods.TbSpecParam;
import com.es.mapper.TbSpecParamMapper;
import com.es.service.TbSpecParamService;
import com.es.utils.BeanHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 * 规格参数组下的参数名 服务实现类
 * </p>
 *
 * @author HM
 * @since 2019-11-29
 */
@Service
public class TbSpecParamServiceImpl extends ServiceImpl<TbSpecParamMapper, TbSpecParam> implements TbSpecParamService {

    @Autowired
    private TbSpecParamService specParamService;

    /**
     * 查询规格的参数
     * @param gid
     * @param cid
     * @return
     */
    @Override
    public List<SpecParamDTO> findSpecParamByGid(Long gid, Long cid, Boolean searching) {
        QueryWrapper<TbSpecParam> queryWrapper = new QueryWrapper<>();
        if(gid != null && gid != 0){
            queryWrapper.lambda().eq(TbSpecParam::getGroupId,gid);
        }
        if(cid != null && cid !=0){
            queryWrapper.lambda().eq(TbSpecParam::getCid,cid);
        }
        if(searching != null){
            queryWrapper.lambda().eq(TbSpecParam::getSearching,searching);
        }

        List<TbSpecParam> tbSpecParamList = specParamService.list(queryWrapper);
        if(CollectionUtils.isEmpty(tbSpecParamList)){
            throw new IndexOutOfBoundsException();
        }
        List<SpecParamDTO> specParamDTOList = BeanHelper.copyWithCollection(tbSpecParamList, SpecParamDTO.class);
        return specParamDTOList;
    }

    /**
     * 查询规格参数
     * @param cid
     * @param gid
     * @return
     */

}
